﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using JasRibbonApplicatie.Classes;
using System.IO;

namespace JasRibbonApplicatie.Views
{
    /// <summary>
    /// Interaction logic for BeheerMateriaal.xaml
    /// </summary>
    public partial class BeheerMateriaal : Page
    {
        jasEntities entities = new jasEntities();
        List<int> toebehorenIdList = new List<int>();
        private String URL = Properties.Settings.Default.HTTP_BASEPATH;
        private Page currentPage;

        public BeheerMateriaal()
        {
            InitializeComponent();
            FillNodes();
            overzichtFrame.NavigationService.LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(NavigationService_LoadCompleted);
            overzichtFrame.Source = new Uri("Omschrijving.xaml",UriKind.Relative);
        }

        public void FillNodes()
        {
            List<TypeMateriaalMetToebehoren> materiaal = Queries.GetAllTypeMateriaalMetToebehoren();
            materiaalTreeView.ItemsSource = materiaal;
            /*
            foreach (var item in materiaal)
            {
                TreeViewItem treeItems = new TreeViewItem();

                treeItems.Header = new Item(item.materiaalType_id, item.Naam);
                foreach (var toebehoren in item.LijstToebehorenTypes)
                {
                    TreeViewItem child = new TreeViewItem();
                    child.Header = new Item(toebehoren.toebehorenType_id, toebehoren.naam);
                    child.Selected += new RoutedEventHandler(childInformation_SelectedItemChanged);
                    treeItems.Items.Add(child);
                }
                materiaalTreeView.Items.Add(treeItems);
            }
            */
        }

        public void ButtonChoice(string buttonName)
        {
            String uri = string.Empty;
            switch (buttonName)
            {
                case "btnshowInfo":
                    uri = "Omschrijving.xaml";
                    break;
                case "btnNieuwMateriaal":
                    uri = "MateriaalToevoegen.xaml";
                    break;
                case "btnCombineMaterials":
                    uri = "ToebehorenLinkMateriaal.xaml";
                    break;
                case "btnAddToebehoren":
                    uri = "ToebehorenToevoegen.xaml";
                    break;
            }

            if (uri != string.Empty)
                overzichtFrame.Source = new Uri(uri, UriKind.Relative);

        }

        private void materiaalTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            if (currentPage.GetType() == typeof(Omschrijving))
            {
                Omschrijving o = currentPage as Omschrijving;
                //als hoofditem (materiaaltype) dan...
                if (materiaalTreeView.SelectedItem.GetType() == typeof(TypeMateriaalMetToebehoren))
                {
                    o.OmschrijvingMateriaal((TypeMateriaalMetToebehoren)materiaalTreeView.SelectedItem);
                }
                else //als niet hoofditem (materiaaltype dan toebehorentype)
                {
                    Console.WriteLine(materiaalTreeView.SelectedItem.GetType());
                    o.OmschrijvingToebehoren((toebehorentypes)materiaalTreeView.SelectedItem);

                }
            }
        }

        public void alertSomething(string msg,string title)
        {
            MessageBox.Show(msg, title, MessageBoxButton.OK, MessageBoxImage.Information);
        }

        void NavigationService_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e)
        {
            currentPage = ((Page)e.Content);
        }

        private void DeleteMenuItem_Click(object sender, RoutedEventArgs e)
        {
            //ToDO
        }
    }
}
